{include file="header/index" /}
<div class="newContentBox">

    <form class="layui-form newListPart" id="myform" enctype="multipart/form-data">
        <input type="hidden" id="id" value="{$id}">
        <div class="newPart">
            <!-- 基本信息 -->
            <div class="newTitleBox">
                <span class="layui-inline newListTitle">基本信息</span>
                <a class="newBtnDefault newBtnGray" onclick="returnBack(this)"> <i class="fa fa-mail-reply"></i>返回</a>
            </div>
            <div class="newContent">
                <div class="layui-form-item cover_layui_f_i">
                    <label class="layui-form-label cover_layui_f_l">姓名：</label>
                    <div class="layui-input-block cover_layui_i_b">
                        <input class="layui-input" id="engineers_name" type="text" name="engineers_name" value="" placeholder="请输入姓名" onkeyup="this.value=this.value.replace(/[^\u4e00-\u9fa5]/g,'')"/>
                    </div>
                </div>
                <div class="layui-form-item cover_layui_f_i">
                    <label class="layui-form-label cover_layui_f_l">身份证号码：</label>
                    <div class="layui-input-block cover_layui_i_b">
                        <input class="layui-input" type="text" name="engineers_idcard" value="" placeholder="请输入身份证号码" onKeyUp="value=value.replace(/[\W]/g,'')"/>
                    </div>
                </div>
                <div class="layui-form-item cover_layui_f_i">
                    <label class="layui-form-label cover_layui_f_l">电话号码：</label>
                    <div class="layui-input-block cover_layui_i_b">
                        <input class="layui-input" id="tel" type="text" name="engineers_phone" placeholder="请输入电话号码" onkeyup="this.value=this.value.replace(/\D/g,'')"/>
                    </div>
                </div>
                <div class="layui-form-item cover_layui_f_i">
                    <label class="layui-form-label cover_layui_f_l">生日：</label>
                    <div class="layui-input-block cover_layui_i_b">
                        <input class="layui-input newDate cover_date" id="birthday" type="text" name="birthday" placeholder="请选择生日"/>
                    </div>
                </div>
                <div class="layui-form-item cover_layui_f_i">
                    <label class="layui-form-label cover_layui_f_l">性别：</label>
                    <div class="layui-input-block cover_layui_i_b">
                        <select name="select" id="gender" class="cover_layui_s">
                            <option value="0">未知</option>
                            <option value="1">男性</option>
                            <option value="2">女性</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item cover_layui_f_i">
                    <label class="layui-form-label cover_layui_f_l">家庭地址：</label>
                    <div class="layui-input-block cover_layui_i_b">
                        <input class="layui-input" id="address" type="text" value="" name="engineers_address" placeholder="请填写家庭地址"/>
                    </div>
                </div>
            </div>
            <!-- 账户信息 -->
            <div class="newTitleBox">
                <span class="layui-inline newListTitle">账户信息</span>
                <div>
                    <a class="layui-btn newBtnDefault" id="editAcount" onclick="editAcount()">修改积分</a>
                    <a href='{:url("Engineers/fundsRecord")}?id={$id}' class="newBtnDefault">账户记录</a>
                </div>
            </div>
            <div class="newContent">
                <div class="layui-form-item cover_layui_f_i">
                    <label class="layui-form-label cover_layui_f_l">状态：</label>
                    <div class="layui-input-block cover_layui_i_b">
                        <select name="select" id="engineers_status" class="cover_layui_s">
                            <option value="1">冻结</option>
                            <option value="2">正常</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item cover_layui_f_i">
                    <label class="layui-form-label cover_layui_f_l">账户积分：</label>
                    <div class="layui-input-block cover_layui_i_b">
                        <input class="layui-input" type="text" name="money" value="" placeholder="请输入账户积分" readonly/>
                    </div>
                </div>
            </div>
            <!-- 其他信息 -->
            <div class="newTitleBox">
                <span class="layui-inline newListTitle">其他信息</span>
            </div>
            <div class="newContent">
                <div class="layui-form-item cover_layui_f_i">
                    <label class="layui-form-label cover_layui_f_l">工程部部门：</label>
                    <div class="layui-input-block cover_layui_i_b">
                        <input class="layui-input" id="department" type="text" name="department" value="" placeholder="请输入工程部部门"/>
                    </div>
                </div>
                <div class="layui-form-item cover_layui_f_i">
                    <label class="layui-form-label cover_layui_f_l">备注：</label>
                    <div class="layui-input-block cover_layui_i_b">
                        <textarea type="text" rows="5" name="note" id="note" class="layui-textarea layui-input"></textarea>
                    </div>
                </div>
            </div>

            <div class="layui-form-item ">
                <div class="layui-input-block cover_layui_i_b">
                    <a class="layui-btn newBtnDefault" onclick="javascript:history.go(-1);">取消</a>
                    <a class="layui-btn newBtnDefault newBtnPrimary" id="btn">编辑</a>
                </div>
            </div>
        </div>

    </form>

</div>

<script>
    var layer = layui.layer,
        element = layui.element,
        laydate = layui.laydate,
        laypage = layui.laypage,
        form = layui.form,
        laytpl = layui.laytpl;
    $.ajaxSetup({headers: {token: $.cookie('token'),company: $.cookie('company_id')}});;
    // 时间日期选择
    $('#birthday').each(function(){
        laydate.render({
            elem: this,
        })
    })

    Ajaxdata();
    function Ajaxdata(){
        var loadingFlag= layer.msg('正在读取数据，请稍候……', { icon: 16, shade: 0.01,shadeClose:false,time:60000 });
        var request_data = {};
        request_data.id = $("#id").val();
        request_data = JSON.stringify(request_data);
        $.post("{:config('api')}/Achievement/Engineers/engineersInfo",request_data,function (flag) {
            layer.close(loadingFlag);
            if (flag.code < 0){
                layer.msg(flag.message,{icon:2,time:1500,shade: 0.1,});
                return false;
            }
            $("input[name='engineers_name']").val(flag.data.engineers_name);
            $("input[name='engineers_idcard']").val(flag.data.engineers_idcard);
            $("input[name='engineers_phone']").val(flag.data.engineers_phone);
            $("input[name='department']").val(flag.data.department);
            $("textarea[name='note']").text(flag.data.note);
            $("#gender").val(flag.data.gender);
            $("#engineers_status").val(flag.data.engineers_status);
            $("input[name='engineers_address']").val(flag.data.engineers_address);
            $("input[name='money']").val(flag.data.money);

            if (flag.data.birthday != 0){
                $("input[name='birthday']").val(flag.data.birthday);
            }else {
                var date = "";
                if(flag.data.engineers_idcard.length == 15) {
                    date =  '19'+flag.data.engineers_idcard.substr(6,2)+'-'+flag.data.engineers_idcard.substr(8,2)+'-'+flag.data.engineers_idcard.substr(10,2);
                } else if (flag.data.engineers_idcard.length == 18) {
                    date =  flag.data.engineers_idcard.substr(6,4)+'-'+flag.data.engineers_idcard.substr(10,2)+'-'+flag.data.engineers_idcard.substr(12,2);
                }
                $("input[name='birthday']").val(date);
            }
        });
    }

    //提交表单
    $("#btn").click(function () {
        var engineers_name = $("input[name='engineers_name']").val();
        var engineers_idcard = $("input[name='engineers_idcard']").val();
        var engineers_phone = $("input[name='engineers_phone']").val();
        var birthday = $("input[name='birthday']").val();
        var note = $("textarea[name='note']").val();
        var engineers_address = $("input[name='engineers_address']").val();
        var gender = $("#gender option:selected").val();
        var engineers_status = $("#engineers_status option:selected").val();
        var department = $("input[name='department']").val();

        if (engineers_name.length == 0){
            top.layer.msg('请输入姓名', {icon: 2});
            return false;
        }
        if (engineers_idcard.length == 0){
            top.layer.msg('请输入身份证', {icon: 2});
            return false;
        }
        if (engineers_phone.length == 0){
            top.layer.msg('请输入电话', {icon: 2});
            return false;
        }
        if (engineers_address.length == 0){
            top.layer.msg('请填写家庭地址', {icon: 2});
            return false;
        }
        var index = layer.load(1, {
            shade: [0.1,'#fff'] //0.1透明度的白色背景
        });
        var request_data = {};
        request_data.engineers_id = $("#id").val();
        request_data.engineers_name = engineers_name;
        request_data.engineers_phone = engineers_phone;
        request_data.engineers_idcard = engineers_idcard;
        request_data.birthday = birthday;
        request_data.gender = gender;
        request_data.note = note;
        request_data.department = department;
        request_data.engineers_address = engineers_address;
        request_data.engineers_status = engineers_status;
        request_data = JSON.stringify(request_data);
        $.post("{:config('api')}/Achievement/Engineers/editEngineers",request_data,function (flag) {
            layer.close(index);
            if (flag.code < 0){
                layer.msg(flag.message,{icon:2,time:1500,shade: 0.1,});
                return false;
            }
            layer.msg(flag.message,{icon:1,time:1500,shade: 0.1,});
            window.location.reload();
        })
    });

    //账户修改
    function editAcount() {
        // var money = $("input[name='money']").val();

        var html = '';
        html +='<form class="layui-form popBox" action="#" method="post">';
        html +='<div class="popChoose">';
        html +='<div class="leftPop">积分：</div>';
        html +='<div class="rightPop">';
        html +='<input class="layui-input" type="text" name="Etotal_money" placeholder="增加或减少积分" id="money" value=""/>';
        html +='</div>';
        html +='</div>';
        html +='<div class="popChoose">';
        html +='<div class="leftPop">备注：</div>';
        html +='<div class="rightPop">';
        html +='<textarea placeholder="请输入备注" rows="2" class="layui-textarea" id="remarks"></textarea>';
        html +='</div>';
        html +='</div>';
        html +='</form>';
        parent.layer.open({
            title:'账户积分修改',
            type: 6,
            area: ['350px', '300px'], //宽高
            shadeClose: false, //点击遮罩关闭
            content: html,
            btn: ['确认', '取消'],
            btnAlign: 'c'
            ,success:function(){
                parent.form.render();
            }
            ,yes: function(index, layero){
                var request_data = {};
                request_data.id = $("#id").val();
                request_data.money = $(layero).find("#money").val();
                request_data.note = $(layero).find("#remarks").val();
                request_data = JSON.stringify(request_data);
                $.post("{:config('api')}/Achievement/Engineers/editMoney",request_data,function (flag) {
                    parent.layer.close(index);
                    if (flag.code < 0){
                        layer.msg(flag.message,{icon:2,time:1500,shade: 0.1,});
                        return false;
                    }
                    layer.msg(flag.message,{icon:1,time:1500,shade: 0.1,});
                    window.location.reload();
                })
            }
            ,btn2: function(index, layero) {
                //按钮【按钮二】的回调
                // return false;//开启该代码可禁止点击该按钮关闭// return true;
            }
            ,cancel: function(){
                //右上角关闭回调
                // return false; //开启该代码可禁止点击该按钮关闭
            }
        });
    }

    $(function(){
        // 焦点事件验证数据是否为空
        $("input[name='engineers_name']").blur(function(){
            var engineers_name = $("input[name='engineers_name']").val();
            if (engineers_name == '') {
                top.layer.msg('姓名不能为空', {icon: 2});
                return false;
            }
        });
        $("input[name='engineers_idcard']").blur(function(){
            var engineers_idcard = $("input[name='engineers_idcard']").val();
            if (engineers_idcard == '') {
                top.layer.msg('身份证号码不能为空', {icon: 2});
                return false;
            }
        });
        $("input[name='engineers_phone']").blur(function(){
            var engineers_phone = $("input[name='engineers_phone']").val();
            if (engineers_phone == '') {
                top.layer.msg('电话号码不能为空', {icon: 2});
                return false;
            }
        });

    })
</script>
